(function ($) {

    function ListView(target, options) {
        this.dbPath = G_Path.contextPath ? G_Path.contextPath : "";

        options = options || {};
        this.target = target;
        this.setting = options;
        this.fieldInfo = options.fieldInfo ? options.fieldInfo : [];
        if (options.eUrl) {
            this.eUrl = this.dbPath + this.setting.eUrl;
        }
        if (options.wUrl) {
            this.wUrl = this.dbPath + this.setting.wUrl;
        }
        if (options.pUrl) {
            this.pUrl = this.dbPath + this.setting.pUrl;
        }
        this.containerElement;
        this.type = {"img": 1, "data": 2};
        this.data = {};
        this.educationData = [];
        this.workData = [];
        this.personData = [];
        this.start = 0;
        this.rowSize = 20;

        this.highlightResult = function () {
            this.style.color = "#00f";
            this.style.backgroundColor = "#ffffd1";
            this.nowUserId = "";
        };
        this.unhighlightResult = function () {
            this.style.color = "#000";
            this.style.backgroundColor = "transparent";
        };
    }

    ListView.DEFAULTS = {
        docStatus: "",
        userRoles: [],
        eUrl: "",
        wUrl: "",
        pUrl: "",
    };
    $.extend(ListView.prototype, {
        show: function () {
            this.getEducation();
        },
        getEducation: function () {
            var self = this;
            var tmpUrl = this.eUrl;
            var educationData = this.setting.param ? this.setting.param : {};
            $.get(tmpUrl, educationData, function (data) {
                var queryPage = $.parseJSON(data);
                if (queryPage && queryPage.list) {
                    self.educationData = queryPage.list;
                    self.getWork();
                }

            });
        },
        getWork: function () {
            var self = this;
            var tmpUrl = this.wUrl;
            var workData = this.setting.param ? this.setting.param : {};
            $.get(tmpUrl, workData, function (data) {
                var queryPage = $.parseJSON(data);
                if (queryPage && queryPage.list) {
                    self.workData = queryPage.list;
                    self.getPerson();
                }

            });
        },
        getPerson: function () {
            var self = this;
            var tmpUrl = this.pUrl;
            var personData = this.setting.param ? this.setting.param : {};
            $.get(tmpUrl, personData, function (data) {
                var queryPage = $.parseJSON(data);
                if (queryPage && queryPage.list) {
                    self.personData = queryPage.list;
                    self.draw();
                }

            });
        },
        draw: function () {
            var self = this;
            $('<div class="zp_divider"><span class="zp_line"></span><span class="zp_dividerName tc">' + "教育经验" + '</span><span class="zp_line"></span></div>').appendTo(this.target);
            for (var key in this.educationData) {
                var file = this.educationData[key];
                $('<div class="zp_personnel_model">').appendTo(this.target);
                $('<div class="zp_personnel_subtitle clearfix">' + file.name + '</div>').appendTo(this.target);
                $('<span class="fr">' + file.startDate + " 毕业" + '</span>').appendTo(this.target);
                $('<span>' + file.educationName + "." + file.major + '</span>').appendTo(this.target);
                $('</div>').appendTo(this.target);
            }
            $('<div class="zp_divider"><span class="zp_line"></span><span class="zp_dividerName tc">' + "工作经验" + '</span><span class="zp_line"></span></div>').appendTo(this.target);
            for (var work in this.workData) {
                var work = this.workData[work];
                $('<div class="zp_personnel_model">').appendTo(this.target);
                $('<div  class="zp_personnel_subtitle clearfix">' + work.name + '</div>').appendTo(this.target);
                $('<span class="fr">' + work.startDate + "-" + work.endDate + '</span>').appendTo(this.target);
                $('<span>' + work.jobName + '</span>').appendTo(this.target);
                $('<span>' + work.content + '</span>').appendTo(this.target);
                $('</div>').appendTo(this.target);
            }
            $('<div class="zp_divider"><span class="zp_line"></span><span class="zp_dividerName tc">' + "自我描述" + '</span><span class="zp_line"></span></div>').appendTo(this.target);
            for (var person in this.personData) {
                var person = this.personData[person];
                $('<div>' + person.content + '</div>').appendTo(this.target);
            }
        }
    });
    $.fn.details = function (options) {
        var listview = new ListView(this, options);
        listview.show();
        return listview;
    };
})(jQuery);